package com.changgou.log.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.log.pojo.SystemLog;
import com.changgou.log.service.SystemLogService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SystemLogController")
@RestController
@RequestMapping("/systemLog")
@CrossOrigin
public class SystemLogController {

    @Autowired
    private SystemLogService systemLogService;

    /***
     * SystemLog分页条件搜索实现
     * @param systemLog
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "SystemLog条件分页查询",notes = "分页条件查询SystemLog方法详情",tags = {"SystemLogController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "SystemLog对象",value = "传入JSON数据",required = false) SystemLog systemLog, @PathVariable  int page, @PathVariable  int size){
        //调用SystemLogService实现分页条件查询SystemLog
        PageInfo<SystemLog> pageInfo = systemLogService.findPage(systemLog, page, size);
        return new Result(true, StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SystemLog分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "SystemLog分页查询",notes = "分页查询SystemLog方法详情",tags = {"SystemLogController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SystemLogService实现分页查询SystemLog
        PageInfo<SystemLog> pageInfo = systemLogService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param systemLog
     * @return
     */
    @ApiOperation(value = "SystemLog条件查询",notes = "条件查询SystemLog方法详情",tags = {"SystemLogController"})
    @PostMapping(value = "/search" )
    public Result<List<SystemLog>> findList(@RequestBody(required = false) @ApiParam(name = "SystemLog对象",value = "传入JSON数据",required = false) SystemLog systemLog){
        //调用SystemLogService实现条件查询SystemLog
        List<SystemLog> list = systemLogService.findList(systemLog);
        return new Result<List<SystemLog>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SystemLog根据ID删除",notes = "根据ID删除SystemLog方法详情",tags = {"SystemLogController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用SystemLogService实现根据主键删除
        systemLogService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SystemLog数据
     * @param systemLog
     * @param id
     * @return
     */
    @ApiOperation(value = "SystemLog根据ID修改",notes = "根据ID修改SystemLog方法详情",tags = {"SystemLogController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "SystemLog对象",value = "传入JSON数据",required = false) SystemLog systemLog, @PathVariable String id){
        //设置主键值
        systemLog.setId(id);
        //调用SystemLogService实现修改SystemLog
        systemLogService.update(systemLog);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SystemLog数据
     * @param systemLog
     * @return
     */
    @ApiOperation(value = "SystemLog添加",notes = "添加SystemLog方法详情",tags = {"SystemLogController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "SystemLog对象",value = "传入JSON数据",required = true) SystemLog systemLog){
        //调用SystemLogService实现添加SystemLog
        systemLogService.add(systemLog);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询SystemLog数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SystemLog根据ID查询",notes = "根据ID查询SystemLog方法详情",tags = {"SystemLogController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public Result<SystemLog> findById(@PathVariable String id){
        //调用SystemLogService实现根据主键查询SystemLog
        SystemLog systemLog = systemLogService.findById(id);
        return new Result<SystemLog>(true,StatusCode.OK,"查询成功",systemLog);
    }

    /***
     * 查询SystemLog全部数据
     * @return
     */
    @ApiOperation(value = "查询所有SystemLog",notes = "查询所SystemLog有方法详情",tags = {"SystemLogController"})
    @GetMapping
    public Result<List<SystemLog>> findAll(){
        //调用SystemLogService实现查询所有SystemLog
        List<SystemLog> list = systemLogService.findAll();
        return new Result<List<SystemLog>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
